﻿Imports Aricie.DNN.Configuration
Imports Aricie.DNN.Modules.LuceneSearch
Imports Aricie.DNN.Modules.LuceneSearch.Business
Imports Aricie.DNN.Services


Namespace Aricie.DNN.Modules.LuceneSearch.Configuration

    Public Class LuceneSearchConfigUpdate
        Implements IUpdateProvider

        Public Function GetConfigElements() As System.Collections.Generic.List(Of Aricie.DNN.Configuration.IConfigElementInfo) Implements Aricie.DNN.Configuration.IUpdateProvider.GetConfigElements
            Dim LuceneSearchConfigElements As New List(Of IConfigElementInfo)

            Dim IndexProviderType As String = "Aricie.DNN.Modules.LuceneSearch.Business.LuceneIndexer, Aricie.DNN.Modules.LuceneSearch"
            Dim indexProvider As New ProviderInfo(Common.Constants.Index.IndexingProviderName, Common.Constants.Index.IndexingAricieProviderName, Aricie.Services.ReflectionHelper.CreateType(IndexProviderType), Common.Constants.Index.IndexingDNNProviderName)
            Dim storeProvider As New ProviderInfo(Common.Constants.Index.DataStoreProviderName, Common.Constants.Index.DataStoreAricieProviderName, GetType(LuceneSearchDataStore), Common.Constants.Index.DataStoreDNNProviderName)

            LuceneSearchConfigElements.Add(indexProvider)
            LuceneSearchConfigElements.Add(storeProvider)

            If Aricie.DNN.Services.NukeHelper.DnnVersion > New Version(5, 3, 0) Then
                'Ajout du provider de sitemap
                Dim typeLuceneSitemapProvider As Type = Aricie.Services.ReflectionHelper.CreateType("Aricie.DNN.Modules.LuceneSearch.SiteMap.LuceneSearchSitemapProvider, Aricie.DNN.LuceneSearchSitemapProvider")
                If typeLuceneSitemapProvider IsNot Nothing Then
                    Dim siteMapProvider As New ProviderInfo(Common.Constants.Index.SiteMapProviderName, Common.Constants.Index.SitemapAricieProviderName, typeLuceneSitemapProvider, Common.Constants.Index.SitemapDNNProviderName)
                    LuceneSearchConfigElements.Add(siteMapProvider)
                End If
            End If

            ' we only add our custom scheduledtask if the dotnetnuke version is high enough to use the new search engine system
            If NukeHelper.DnnVersion >= New Version(7, 1, 0) Then
                LuceneSearchConfigElements.Add(New SchedulerTaskElementInfo("LuceneSearch indexation task", GetType(Scheduling.ScheduledIndexation), New TimeSpan(0, 30, 0)))
            End If

            Return LuceneSearchConfigElements
        End Function
    End Class

End Namespace